<template>
    <div class="login-wrap">
        <div class="ms-login">
            <div class="ms-title">欢迎使用萧山工单项目系统</div>
            <el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
                <el-form-item prop="username">
                    <el-input v-model="param.username" placeholder="请输入用户名">
                        <template #prepend>
                            <el-button icon="el-icon-user"></el-button>
                        </template>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password" placeholder="请输入用户密码" v-model="param.password" @keyup.enter="submitForm()" show-password>
                        <template #prepend>
                            <el-button icon="el-icon-lock"></el-button>
                        </template>
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm()">登录</el-button>
                </div>
                <p class="login-tips">© 版权所有 国网浙江杭州市萧山区供电有限公司<br>
                  地址：浙江省杭州市萧山城厢镇萧绍路189号</p>
            </el-form>
        </div>
    </div>
</template>

<script>
import {loginTable} from '../../api/api';
export default {
    data() {
        return {
            param: {
                username: "",
                password: ""
            },
            rules: {
                username: [
                    { required: true, message: "请输入用户名", trigger: "blur" }
                ],
                password: [
                    { required: true, message: "请输入密码", trigger: "blur" }
                ]
            }
        };
    },
    created() {
        this.$store.commit("clearTags");
    },
    methods: {
        submitForm() {
            this.$refs.login.validate(valid => {
                if (valid) {
                    let loginForm = {
                      sdUserId: this.param.username,
                      sdUserPassword: this.param.password
                    }
                    console.log(loginForm)
                    loginTable(loginForm).then((res) => {
                      console.log('密码', res.data)
                      if (res.data.status == 200){
                        localStorage.setItem('token', JSON.stringify(res.data.data))
                        localStorage.setItem("ms_username", this.param.username);
                        this.$message.success("登录成功");
                        this.$router.push("/dashboard");
                      }else{
                        this.$message.error('用户账号/用户密码格式不正确');
                      }
                    })
                } else {
                    this.$message.error("请输入账号和密码");
                    return false;
                }
            });
        }
    }
};
</script>

<style scoped>
.login-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../../assets/img/login1.jpeg);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 60px;
    text-align: center;
    font-size: 25px;
    color: #fff;
    /*color: rgba(0, 0, 0, 0.5);*/
    border-bottom: 2px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 47%;
    top: 50%;
    width: 450px;
    /*height: 300px;*/
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    /*background: rgba(255, 255, 255, 0.3);*/
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    text-align: center;
    font-size: 13px;
    line-height: 20px;
    color: #fff;
}
</style>
